home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / RAND / DVIEW000.LZH / C2P.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-10  |  3.7 KB  |  192 lines

  1. #define C
  2.  
  3. #if 1
  4. #define SLOW
  5. #endif
  6.  
  7. #ifdef __GNUC__
  8. #include <osbind.h>
  9. #else
  10. #include <tos.h>
  11. #endif
  12. #include <linea.h>
  13. #include <string.h>
  14. #include <stdio.h>
  15.  
  16. #ifndef C
  17. extern "C" {
  18. #endif
  19.  
  20. #ifdef __GNUC__
  21. void debit4plane(char *, short, short, short, short *, short);
  22. void debitplane(char *, short, short, short, short *, short);
  23. #endif
  24.  
  25. #ifndef C
  26. }
  27. #endif
  28.  
  29. #ifndef SLOW
  30. char vgabuf[64000];
  31. #endif
  32.  
  33. long  Scr_Offtop;
  34. long  Scr_Offbot;
  35. long  Scr_Size;
  36. char  *_Scrn;        /* Screen buffers */
  37.  
  38. int   v_x_max;
  39. int   v_y_max;
  40. int   vplanes = 0;
  41. int   vwrap;
  42.  
  43. void init_sc(void)
  44. {
  45.    long phy, log;
  46.  
  47. #ifdef __GNUC__
  48.    linea0();
  49.    v_x_max = V_X_MAX;
  50.    v_y_max = V_Y_MAX;
  51.    vplanes = VPLANES;
  52.    vwrap   = VWRAP;
  53. #else
  54.    linea_init();
  55.    v_x_max = Vdiesc->v_rez_hz;      /* Not as in help documentation! */
  56.    v_y_max = Vdiesc->v_rez_vt;      /* Not as in help documentation! */
  57.    vplanes = Linea->v_planes;
  58.    vwrap   = Linea->v_lin_wr;
  59. #endif
  60.  
  61.    /*
  62.     * Get screen parameters, insure multiple of 256 bytes
  63.     */
  64.  
  65.    phy = (long)Physbase();
  66.    log = (long)Logbase();
  67.    Scr_Offtop = (long)log-phy;
  68.    Scr_Size = (long)vwrap * (long)v_y_max + Scr_Offtop;
  69.    Scr_Offbot = ((Scr_Size + 255) & 0xffffff00L) - Scr_Size;
  70.    if (Scr_Offtop)
  71.       Scr_Offbot += 256;
  72.    Scr_Size += Scr_Offbot;
  73.  
  74.    _Scrn = (char *)phy;
  75. }
  76.  
  77. void c2p(char *buf, int w_area, int h_area)
  78. {
  79.  
  80. /*
  81.  * Show image in colour.
  82.  */
  83.  
  84.    long     yoffset, rowoffset;
  85.    short    x, y;
  86.    short    *screen, *wordpos;
  87.    unsigned short q, pix;
  88.    char     *p;
  89.  
  90.    if (vplanes == 0)
  91.       init_sc();
  92.  
  93. #ifdef SLOW
  94.    screen = (short *)_Scrn;
  95. #else
  96.    screen = (short *)vgabuf;
  97. #endif
  98.  
  99.    /*
  100.     *   yoffset positions us into the screen which is an int array.
  101.     */
  102.  
  103. #ifdef SLOW
  104.    yoffset = Scr_Offtop >> 1;
  105. #else
  106.    yoffset = 0;
  107. #endif
  108.  
  109. #ifdef __GNUC__
  110.    if (vplanes == 4) {
  111.       debit4plane(buf, w_area, w_area, h_area,
  112.                   &screen[yoffset], vwrap);
  113. #if 0
  114.       return;
  115. #endif
  116.    } else if (vplanes == 8) {
  117.       debitplane(buf, w_area, w_area, h_area,
  118.                  &screen[yoffset], vwrap);
  119. #if 0
  120.       return;
  121. #endif
  122.    } else {
  123. #endif
  124.       rowoffset = 0;
  125.  
  126.       /*
  127.        *   Loop over all rows in image
  128.        */
  129.  
  130.       for (y = 0;y < h_area;y++) {
  131.          /*
  132.           *   Set ptr to this pixel row
  133.           */
  134.  
  135.          p       = buf + rowoffset;
  136.          wordpos = &screen[yoffset];      /* + vpanes - 1 ? */
  137.  
  138.          /*
  139.           *   Loop over all pixels in the row
  140.           */
  141.  
  142. #ifdef SLOW
  143.          memset(wordpos, 0, vwrap);
  144. #else
  145.          memset(wordpos, 0, 320 / 2);
  146. #endif
  147.  
  148.          pix = 0x8000;
  149.          for (x = w_area;x > 0;x--) {
  150.             q = *p++;
  151.             if (q & 0x04)
  152.                wordpos[2] |= pix;
  153.             if (q & 0x08)
  154.                wordpos[3] |= pix;
  155.             if (q & 0x02)
  156.                wordpos[1] |= pix;
  157.             if (q & 0x01)
  158.                wordpos[0] |= pix;
  159.  
  160.             if (!(pix >>= 1)) {
  161.                wordpos += vplanes;
  162.                pix = 0x8000;
  163.             }
  164.          }
  165.  
  166.          /*
  167.           *   Get ready for next row by incrementing offset into
  168.           *   the screens.
  169.           */
  170.  
  171. #ifdef SLOW
  172.          yoffset += vwrap >> 1;
  173. #else
  174.          yoffset += (320 / 2) >> 1;
  175. #endif
  176.          rowoffset += w_area;
  177.       }
  178. #ifdef __GNUC__
  179.    }
  180. #endif
  181. #ifndef SLOW
  182.    screen = (short *)_Scrn;
  183.    yoffset = Scr_Offtop >> 1;
  184.    rowoffset = 0;
  185.    for(y = 0;y < h_area;y++) {
  186.       memmove(&screen[yoffset], &vgabuf[rowoffset], 320 / 2);
  187.       yoffset += vwrap >> 1;
  188.       rowoffset += 320 / 2;
  189.    }
  190. #endif
  191. }
  192.